#include "Driver_LPTIM16.h"

/**
 * @brief LPTIM16 模块初始化, 100ms触发一次中断
 *
 */
void Driver_LPTIM16_Init(void)
{
    FL_LPTIM16_InitTypeDef timInit;

    /*---------------- 定时器时间基准配置 ----------------*/
    FL_LPTIM16_StructInit(&timInit);

    timInit.clockSource          = FL_CMU_LPTIM16_CLK_SOURCE_APBCLK;
    timInit.mode                 = FL_LPTIM16_OPERATION_MODE_NORMAL;
    timInit.prescalerClockSource = FL_LPTIM16_CLK_SOURCE_INTERNAL;
    timInit.prescaler            = FL_LPTIM16_PSC_DIV128;
    timInit.autoReload           = 50000 - 1;
    timInit.encoderMode          = FL_LPTIM16_ENCODER_MODE_DISABLE;
    timInit.onePulseMode         = FL_LPTIM16_ONE_PULSE_MODE_CONTINUOUS;
    timInit.triggerEdge          = FL_LPTIM16_ETR_TRIGGER_EDGE_RISING;
    timInit.countEdge            = FL_LPTIM16_ETR_COUNT_EDGE_RISING;
    FL_LPTIM16_Init(LPTIM16, &timInit);

    /*---------------- 中断配置 ----------------*/
    /* 清除标志 */
    FL_LPTIM16_ClearFlag_Update(LPTIM16);

    /* 中断使能 */
    FL_LPTIM16_EnableIT_Update(LPTIM16);

    /* 使能并配置NVIC */
    NVIC_DisableIRQ(LPTIMx_IRQn);
    NVIC_SetPriority(LPTIMx_IRQn, 4); /* 设置中断优先级 */
    NVIC_EnableIRQ(LPTIMx_IRQn);
    /*---------------------------------------------*/

    /* 使能LPTIM16 */
    FL_LPTIM16_Enable(LPTIM16);
}
